/*
 * @Author      : ZhouQiJun
 * @Date        : 2025-08-06 21:24:33
 * @LastEditors : ZhouQiJun
 * @LastEditTime: 2025-08-21 04:04:12
 * @Description :
 */
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { URL, fileURLToPath } from 'node:url'
import dts from 'unplugin-dts/vite'
import { defineConfig } from 'vite'

// https://vite.dev/config/
export default defineConfig(({ command, mode, isPreview }) => {
  return {
    plugins: [
      vue(),
      vueJsx(),
      dts({
        copyDtsFiles: true,
        bundleTypes: true,
        tsconfigPath: './tsconfig.app.json',
      }),
    ],
    resolve: {
      alias: {
        '@e': fileURLToPath(new URL('./examples', import.meta.url)),
        '@ol': fileURLToPath(new URL('./src', import.meta.url)),
        //'#ol-vue-hooks': './src/index.ts', //fileURLToPath(new URL('./src/index.ts', import.meta.url)),
        '#ol-vue-hooks': fileURLToPath(new URL('./src/index.ts', import.meta.url)),
      },
    },
    build: {
      minify: false,
      lib: {
        entry: 'src/index.ts', // 设置入口文档
        //name: 'OVH', // 起个名字，安装、引入用
        fileName: (format) => `ovh.${format}.js`, // 打包后的文档名
        formats: ['es'],
      },
      rollupOptions: {
        external: [
          /^es-toolkit(\/.*)?$/,
          'gcoord',
          /^ol(\/.*)?$/,
          /^ol-ext(\/.*)?$/,
          'cesium',
          'proj4',
          'vue',
          'petite-utils',
        ],
        //external: [/node_modules/],
        //external: ['es-toolkit', 'gcoord', 'ol', 'cesium', 'proj4', 'vue', 'petite-utils'], // 排除不需要打包的依赖
        //output: {
        //  globals: {
        //    'es-toolkit': '_',
        //    ol: 'ol',
        //    gcoord: 'gcoord',
        //    proj4: 'proj4',
        //    cesium: 'cesium',
        //    vue: 'Vue',
        //    'petite-utils': 'PU',
        //  },
        //},
      },
    },
    css: {
      devSourcemap: command === 'serve',
    },
    server: {
      open: true,
    },
  }
})
